
// 98.验证二叉搜索树
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    bool isValidBST(TreeNode* root) {
        
        function<bool(TreeNode* , long  , long)> check = [&](TreeNode* pos , long maxi , long mini)
        {
            if(pos == nullptr) return true;
            if(pos->val <= mini || pos->val >= maxi) return false;
            return check(pos->left , pos->val , mini) && check(pos->right , maxi , pos->val);
        };
        return check(root , LONG_MAX , LONG_MIN);
    }
};